﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    @*Easyui需要引入的文件*@
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.5/jquery.min.js"></script>
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.5/jquery.easyui.min.js"></script>
    <link href="~/Content/jquery-easyui-1.4.5/themes/default/easyui.css" rel="stylesheet" />
    <link href="~/Content/jquery-easyui-1.4.5/themes/icon.css" rel="stylesheet" />
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <script src="~/Scripts/messages_zh.js"></script>
    <script type="text/javascript" src="~/Content/Site.js"></script>

    <script type="text/javascript">
        $(function () {
            //初始化datagrid
            InitGrid();
            InitDialog();
            $('#btnReload').click(function () {
                $("#grid").datagrid("reload");
            });
            //ajax提交修改表单
            $('#ok').click(function () {
                $('#form').submit();
            });
            $('#cancel').click(function () {
                $('#dd').dialog('close');
            });
            $('#add').click(function () {
                $('#form')[0].reset();
                $('#ID').val("此字段自动生成。");
                $('#dd').dialog('open');
            });
            $('#del').click(function () {
                getAjax("../PSS_ExWarehouseMode/Del", { id: $('#del_id').val() }, function (data) {
                    if ($('#del_id').val() == null || $('#del_id').val() == "")
                        return false;
                    if (data) {
                        $.messager.alert('提示', '操作失成功!');
                        $('#dd').dialog('close');
                        $("#grid").datagrid("reload");
                        return true;
                    }
                    else {
                        $.messager.alert('提示', '操作失败!');
                        return false;
                    }
                });
            });
        });

        //实现对DataGird控件的绑定操作
        function InitGrid() {
            $('#grid').datagrid({
                url: '../PSS_ExWarehouseMode/LoadList',
                fit:true,
                nowrap: true,//单行显示
                autoRowHeight: false,
                striped: false,     //斑马纹
                singleSelect: true,
                collapsible: true,      //可折叠
                pagination: true,
                pageSize: 20,
                fitColumns: true,       //自适应列宽
                rownumbers: true,
                columns: [[
                     { title: '编号', field: 'ID', hidden: true },
                     { title: '出库方式', field: 'Name', width: 10 },
                     { title: '对应方式', field: 'Way', width: 10 },
                ]],
                toolbar: '#tb',
                onDblClickRow: function (rowIndex, rowData) {
                    getAjax("../PSS_ExWarehouseMode/LoadForm",
                        { id: rowData['ID'] }, function (data) {
                            var data = eval("(" + data + ")");
                            SetWebControls(data);
                        });
                    $('#dd').dialog('open');
                },
                onClickRow: function (index, row) {
                    $('#del_id').val(row['ID']);
                }
            })
            var p = $('#grid').datagrid('getPager');
            $(p).pagination({
                beforePageText: '第',
                afterPageText: '页   共 {pages} 页',
                displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
            });
        };

        function InitDialog() {
            $('#dd').dialog({
                title: '修改信息',
                width: 400,
                height: 180,
                top: ($(window).height() - 200) * 0.5,      //居中
                left: ($(window).width() - 400) * 0.5,
                closed: true,
                cache: false,
                modal: true,
                buttons: '#dlg-buttons'
            });
        }


    </script>
    <script>
        //表单验证和提交
        $(function () {
            $('#form').validate({
                rules: {
                    Name: {
                        required: true
                    }
                },
                submitHandler: function (form) {
                    var postData = GetWebControls("#form");
                    getAjax("/PSS_ExWarehouseMode/AcceptClick",
                        postData, function (data) {
                            if (data) {
                                $.messager.alert('提示', '操作成功!');
                                $('#dd').dialog('close');
                                $("#grid").datagrid("reload");
                                return true;
                            }
                            else {
                                $.messager.alert('提示', '操作失败!');
                                return false;
                            }
                        });
                },
                invalidHandler: function (form, validator) {  //不通过回调
                    return false;
                },
                showErrors: function (errorMap, errorList) {
                    this.defaultShowErrors();
                    for (var i = 0; i < errorList.length; i++) {
                        $(errorList[i].element).one("blur", function () {
                            $("label.error[for='" + (this.id ? this.id : this.name) + "']").remove();
                        });
                    }
                }
            });
        });
    </script>
</head>
<body style="margin:2px;padding:0">
    <div>
        <input id="del_id" type="hidden" name="del_id" value=" " />
        <div style="position:fixed;width:100%;height:100%">
            <table id="grid"></table>
        </div>
        <div id="tb" style="padding:3px">
            <a id="add" href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'">新增</a>
            <a id="del" href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-remove'">删除</a>
            <a id="btnReload" href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-reload'">刷新</a>
        </div>
    </div>
    <div id="dd" class="easyui-dialog">
        <form id="form" name="form" method="post">
            <table style="margin:8px">
                <tr>
                    <td>编号:</td>
                    <td><input type="text" id="ID" name="ID" value=" " disabled="disabled" /></td>
                </tr>
                <tr>
                    <td>出库方式:</td>
                    <td><input type="text" id="Name" name="Name" value="" class="required" /></td>
                </tr>
                <tr>
                    <td>对应方式:</td>
                    <td><input type="text" id="Way" name="Way" value=" " /></td>
                </tr>
            </table>
            <div id="dlg-buttons">
                <a id="ok" href="#" class="easyui-linkbutton" iconcls="icon-ok">确定</a>
                <a id="cancel" href="#" class="easyui-linkbutton" iconcls="icon-cancel">取消</a>
            </div>

        </form>
    </div>
</body>
</html>
